// 增加购买商品数量
function addC(e, p) {
    let n = document.getElementById("buy-num"+e);
    n.value = +n.value + 1;

    document.getElementById("price"+e).innerText = "￥" + (n.value * p);
    zj()
}

// 减少购买商品数量
function decC(e, p) {
    let n = document.getElementById("buy-num"+e);
    // 最低1件
    if (+n.value > 1) {
        n.value = +n.value - 1;
        document.getElementById("price"+e).innerText = "￥" + (n.value * p);
    }
    zj()
}

// 删除
function del(e) {
    let a = document.getElementById("buy_"+e);
    a.parentNode.removeChild(a);
    zj();
    bCount();
}

// 全选
function xz() {
    // noinspection SpellCheckingInspection
    let s = document.getElementsByName("sele");

    let c = true;

    for (let i = 0; i < s.length; i++) {
        if (!s[i].checked)
            c = false;
    }

    if (c) {    // 全不选
        for (let i = 0; i < s.length; i++)
            s[i].checked = false;
    } else {    // 全选
        for (let i = 0; i < s.length; i++)
            if (!s[i].checked)
                s[i].checked = true;
    }
}

// 总价格
function zj() {
    let len = document.getElementById("ul-c").getElementsByTagName("li").length;
    let z = 0;

    for (let i = 0; i < len; i++) {
        let p = document.getElementById("price" + (i +1));
        z = +p.innerText.substring(1, p.innerText.length) + z;
    }

    document.getElementById("J_totalMoney").innerText = z;
    document.getElementById("J_totalMoney2").innerText = z;
}

// 删除已选
function delX() {
    let s = document.getElementsByName("sele");

    for (let i = 0; i < s.length; i++) {
        if (s[i].checked) {
            let n = s[i].parentNode.parentNode;
            n.parentNode.removeChild(n);
            i--;
        }
    }

    zj();
    bCount();
}

function bCount() {
    // 实时商品数量显示
    document.getElementById("J_totalProductCount").innerText = document.getElementById("ul-c").getElementsByTagName("li").length;
}

// 提交订单
function tj(path) {
    let seles = document.getElementsByName("sele");
    var str = "";

    for (let i = 0; i < seles.length; i++) {
        str += seles[i].value + "-";
    }

    location.href = path + "/book?method=balance&seles=" + str;
}